//
//  SISSUploadPictureBottomInfoViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/10/25.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSUploadPictureBottomInfoViewController.h"
#import "SISSTitleView.h"
#import "SISSUploadImageView.h"

#import "SISSUploadPictureBottomInfoShowViewController.h"

@interface SISSUploadPictureBottomInfoViewController ()<YYTextViewDelegate,SISSUploadImageViewDelegate>

@property (weak, nonatomic) SISSTitleView *titleView;
@property (weak, nonatomic) SISSUploadImageView *uploadImageView;

@property (weak, nonatomic) SISSTitleView *infoTitleView;
@property (weak, nonatomic) YYTextView *infoTextView;

// 确定
@property (weak, nonatomic) UIButton *confirmButton;


@end

@implementation SISSUploadPictureBottomInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)setTitleStr:(NSString *)titleStr {
    _titleStr = titleStr;
    self.titleView.titleStr = titleStr;
}

- (void)setInfoTitleStr:(NSString *)infoTitleStr {
    _infoTitleStr = infoTitleStr;
    self.infoTitleView.titleStr = infoTitleStr;
}

- (void)setInfoStr:(NSString *)infoStr {
    _infoStr = infoStr;
    self.infoTextView.text = infoStr;
}



#pragma mark -- YYTextViewDelegate
- (void)textViewDidEndEditing:(YYTextView *)textView {
    self.infoStr = textView.text;
}

- (void)textViewDidBeginEditing:(YYTextView *)textView {
    self.infoStr = textView.text;
}

#pragma mark - SISSUploadImageViewDelegate
- (void)handlePhotoFinishedAction {
    self.images = self.uploadImageView.images;
}

// 确定按钮点击事件
- (void)confirmButtonClickAction {
    
    SISSUploadPictureBottomInfoShowViewController *vc = [[SISSUploadPictureBottomInfoShowViewController alloc] init];
    vc.images = self.images;
    vc.infoStr = self.infoStr;
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    SISSTitleView *titleView = [[SISSTitleView alloc] init];
    titleView.titleStr = @"上传公证书";
    [self.view addSubview:titleView];
    self.titleView = titleView;
    
    SISSUploadImageView *uploadImageView = [[SISSUploadImageView alloc] init];
    uploadImageView.isHiddenTitle = YES;
    uploadImageView.delegate = self;
    [self.view addSubview:uploadImageView];
    self.uploadImageView = uploadImageView;
    
    SISSTitleView *infoTitleView = [[SISSTitleView alloc] init];
    infoTitleView.titleStr = @"补充说明";
    [self.view addSubview:infoTitleView];
    self.infoTitleView = infoTitleView;
    
    YYTextView *infoTextView = [[YYTextView alloc] init];
    infoTextView.placeholderText = @"补充说明";
    infoTextView.placeholderFont = [UIFont systemFontOfSize:15];
    infoTextView.font = [UIFont systemFontOfSize:15];
    infoTextView.delegate = self;
    [self.view addSubview:infoTextView];
    self.infoTextView = infoTextView;
    if (self.infoStr.length) {
        self.infoTextView.text = self.infoStr;
    }
    
    UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [confirmButton setTitle:@"确定" forState:UIControlStateNormal];
    [confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [confirmButton setBackgroundColor:MAIN_COLOR];
    [confirmButton addTarget:self action:@selector(confirmButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    confirmButton.layer.cornerRadius = 4;
    confirmButton.layer.masksToBounds = YES;
    [self.view addSubview:confirmButton];
    self.confirmButton = confirmButton;
}

- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf;
    CGSize buttonSize = CGSizeMake(SCREEN_WIDTH * 0.8, 40);
    [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.mas_topLayoutGuideBottom);
        make.left.right.equalTo(weakSelf.view);
        make.height.mas_equalTo(5 * globelMargin);
    }];
    
    [self.uploadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.titleView.mas_bottom).offset(2 * globelMargin);
        make.left.right.equalTo(weakSelf.view);
    }];
    
    [self.infoTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.uploadImageView.mas_bottom).offset(2 * globelMargin);
        make.left.right.equalTo(weakSelf.view);
        make.height.mas_equalTo(5 * globelMargin);
    }];
    
    [self.infoTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.infoTitleView.mas_bottom).offset(2 * globelMargin);
        make.left.equalTo(weakSelf.view).offset(2 * globelMargin);
        make.right.equalTo(weakSelf.view).offset(-2 * globelMargin);
        make.height.mas_equalTo(10 * globelMargin);
    }];
    
    [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.infoTextView.mas_bottom).offset(8 * globelMargin);
        make.centerX.equalTo(weakSelf.view.mas_centerX);
        make.size.mas_equalTo(buttonSize);
    }];
    
}

@end
